package main

import (
	"flag"
	"fmt"
	"gitee.com/jn-qq/multi_threader"
	"os"
	"path/filepath"
)

var m3u8Path = flag.String("u", "", "必选。m3u8 文件路径、链接或文本")
var m3u8Prefix = flag.String("bu", "", "可选。ts 文件拼接路径")
var mp4 = flag.Bool("mp4", true, "可选，默认true。是否转换为mp4格式")
var tn = flag.Int("tn", 10, "可选，默认10。下载线程数")
var fn = flag.String("o", "", "保存文件名")
var translate = flag.Bool("t", false, "可选，仅执行ts->mp4转换程序")

func init() {
	flag.Parse()
	if *fn == "" {
		fmt.Print("请输入保存文件名：")
		_, _ = fmt.Scanln(fn)
	}
	_ = os.Mkdir(filepath.Join(".cache", *fn), 0777)
}

func main() {
	m3 := &m3u8Flow{
		url:     *m3u8Path,
		baseUrl: *m3u8Prefix,
	}

	if !*translate {
		multi_threader.NewPool(*tn).EnablePrint(false).Run(m3)
	}

	if *mp4 {
		m3.ToMp4()
	}

}
